package top.kaoshanji.p1ch11a;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 代码清单-p1ch11a-380页a：显示一个目录项
 * URL访问地址：/nileItem
 * @author kaoshanji
 * ^_^
 * create time 2025/4/5 16:15
 */
public class NileItem extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        // 没有设置内容类型
        PrintWriter out = resp.getWriter();

        Book book = (Book)req.getAttribute("item");

        out.println("<BR>");
        if (book != null) {
            out.println("<I>" + book.getTitle() + "</I>");
            out.println(" by " + book.getAuthor());
        }
        else {
            out.println("<I>No book record found</I>");
        }
        out.println("<BR>");

    }

}
